package com.example.ymm.modules1.service.impl.hl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.ymm.base.BaseServiceImpl;
import com.example.ymm.model.TableList;
import com.example.ymm.model.YmPageDto;
import com.example.ymm.modules1.entity.hl.yw.YwCommissionConfig;
import com.example.ymm.modules1.mapper.hl.YwCommissionConfigMapper;
import com.example.ymm.modules1.query.hl.YwCommissionConfigQueryCriteria;
import com.example.ymm.modules1.service.hl.YwCommissionConfigService;
import com.example.ymm.util.QueryHelpPlus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
@DS("slave2")
public class YwCommissionConfigServiceImpl extends BaseServiceImpl<YwCommissionConfigMapper, YwCommissionConfig>
        implements YwCommissionConfigService {

    @Override
    public TableList<YwCommissionConfig> list(YwCommissionConfigQueryCriteria criteria, YmPageDto pageDto) {
        IPage<YwCommissionConfig> page = new Page<YwCommissionConfig>(pageDto.getPage(), pageDto.getPageSize());
        QueryWrapper predicate = QueryHelpPlus.getPredicate(YwCommissionConfig.class, criteria);
        predicate.orderByDesc("create_time");
        baseMapper.selectPage(page, predicate);
        TableList<YwCommissionConfig> tableList = new TableList(page);
        return tableList;
    }

    public List<YwCommissionConfig> queryAll(YwCommissionConfigQueryCriteria criteria) {
        QueryWrapper predicate = QueryHelpPlus.getPredicate(YwCommissionConfig.class, criteria);
        predicate.orderByDesc("create_time");
        List<YwCommissionConfig> result = baseMapper.selectList(predicate);
        return result;
    }
}
